package pms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import pms.dao.ReservierungDao;
import pms.dto.ResEventKundeDTO;


/** 
 * <p>
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
 * </p>
 * 
 * <p>
 * ModelAndView contains
 * <ul>
 * <li>title: Will be used as a headline in the resulting view</li>
 * <li>message: Some hints for the user</li>
 * </ul>
 * The name of the selected view will be: 'list-buchungen.jsp'.
 * </p>
 * 
 * @author KRS DEV Team (krsdevteam@PMSWIbb2011SS.de)
 */
public class AlleBuchungen extends AbstractController {
    private static Log log = LogFactory.getLog(AlleBuchungen.class);
	private ReservierungDao reservierungDao;

	
	public void setReservierungDao(ReservierungDao reservierungDao) {
		this.reservierungDao = reservierungDao;
	}
	
	public ReservierungDao getReservierungDao() {
		return reservierungDao;
	}
	
	protected ModelAndView handleRequestInternal(
			HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		log.info(httpServletRequest.getPathTranslated());
		
		ModelAndView mv = new ModelAndView();
		mv.addObject("privileged", httpServletRequest.isUserInRole("admin"));
		mv.addObject("title", "Ticketreservierungen");
		mv.addObject("message", "Übersicht über alle gebuchten Reservierungen.");
		//List<Reservierung> dieReservierung = reservierungDao.findAll();
		List<ResEventKundeDTO> res = reservierungDao.findAllVoll();
		mv.addObject("reservierungen", res);
		mv.addObject("edit", true);
		mv.setViewName("list-buchungen");
		//log.debug(dieReservierung.size());
		return mv;
	}

}
